<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-3.6.3.min.js"></script>
    <script>
        $(function () {
           $("form").submit(function () {
               let d=document.getElementById("form1");
               let formdata=new FormData(d);
               $.ajax({
                   url:"adv/add",
                   data:formdata,
                   type:"post",
                   processData:false,
                   contentType:false,
                   success:function(result){
                       if(result.code==0){
                          alert("ok");
                       }else{
                           alert(result.msg);
                       }
                   },
                   error:function(e){
                       alert(e);
                   }
               });
               return false;
           });
        });
    </script>
</head>
<body>
<form class="layui-form" id="form1" action="add" method="post" enctype="multipart/form-data">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" required name="title" lay-verify="title"  placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网址</label>
                    <div class="layui-input-block">
                        <input type="text"  name="url" lay-verify="title"  placeholder="请输入网址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="number" value="1" min="1" name="sortorder" lay-verify="sortorder" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">是否启用</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="isvalid" value="true" lay-skin="switch" lay-text="启用|停用" checked>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图片</label>
                    <div class="layui-input-block">
                        <input type="text"   name="imgurl"   placeholder="图片地址" class="layui-input">
                        <input type="file"  id="imgurl" name="a_imgurl"   placeholder="选择一个图片" class="layui-input">
                    </div>
                    <div class="layui-input-block">
                        <img src="" id="preivew" style="height: 50px;width: 140px;"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">打开方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="target" value="_self" title="本页打开">
                        <input type="radio" name="target" value="_blank" title="新窗口打开" checked>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
</html>